package com.lancoo.znbkxx.teacher.aibkTestCoach.aibkDialog

import android.app.Activity
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import androidx.appcompat.app.AppCompatDialog
import androidx.databinding.DataBindingUtil
import androidx.databinding.ObservableField
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.databinding.RemindDialogBinding
import com.lancoo.znbkxx.teacher.ui.Presenter
import com.lancoo.znbkxx.teacher.utils.DensityUtils.dp2px
import com.lancoo.znbkxx.teacher.utils.DensityUtils.getScreenWidth

/**
 * Created by Dadong on 2019-12-23
 * Describe:
 */
class RemindDialog(private val mContext: Context,
                   private val mActivity: Activity,
                   style: Int = R.style.AppTheme_CommonDialog) : AppCompatDialog(mContext, style), Presenter {


    val message = ObservableField<String>()
    private lateinit var clickListener: OnClickListener

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setCanceledOnTouchOutside(false)
        setCancelable(false)
//        setWidthAndHeight()
        window!!.setWindowAnimations(android.R.style.Animation_Dialog)
    }

    private fun setWidthAndHeight() {
        val lp = window!!.attributes
        lp.width = getScreenWidth(mActivity) - dp2px(mContext, 30f)
        window!!.attributes = lp
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.beta_confirm_button -> {
                clickListener.onConfirm()
                dismiss()
            }
        }
    }

    override fun onCancel(view: View?) {
        when (view?.id) {
            R.id.beta_cancel_button -> {
                clickListener.onCancel()
                dismiss()
            }
        }
    }

    val mBinding: RemindDialogBinding by lazy {
        DataBindingUtil.inflate<RemindDialogBinding>(
                LayoutInflater.from(mContext), R.layout.remind_dialog, null, false)
    }

    init {
        setContentView(mBinding.root)
        mBinding.presenter = this
    }

    fun setOnClickListener(clickListener: OnClickListener): RemindDialog {
        this.clickListener = clickListener
        return this
    }

    interface OnClickListener {
        fun onConfirm()
        fun onCancel()
    }

}